<template>
    <h2>显示列表</h2>
    医生名称<input type="text" v-model="DoctorName">
    职称<select v-model="Pos">
                    <option value="主任医师">主任医师</option>
                    <option value="副主任">副主任</option>
                    <option value="医生">医生</option>
                </select>
    <input type="button" value="查询" @click="Lodata">

    <input type="button" value="导出" @click="Exopre">
<table border="1">
    <thead>
        <tr>
            <td>医生编号</td>
            <td>医生名称</td>
            <td>学历</td>
            <td>职称</td>
            <td>医生照片</td>           
            <td>科室名称</td>
            <td>操作</td>
        </tr>  
    </thead>
    <tbody>
        <tr v-for="item in info">
            <td>{{item.DoctorId}}</td>
            <td>{{item.DoctorName}}</td>
            <td>{{item.College}}</td>
            <td>{{item.Pos}}</td>
            <td><img style="width: 60px;height: 60px;" :src="item.DoctorImg"></td>           
            <td>{{item.KeiShiName}}</td>
            <td>操作
                <a style="margin-right: 20px;" @click="Del(item.DoctorId)">删除</a>
                <a style="margin-right: 20px;" @click="Get(item.DoctorId)">查看医生个人简历</a>
            </td>
        </tr>  
    </tbody>
      
</table>

当前共{{ pageInfo.totalcount }}条,当前页共{{ pageInfo.pageSize }}条
当前页共{{ pageInfo.pageIndex }}/{{ pageInfo.pagecount }}页
<span>
    <a style="margin-right: 20px;" @click="pageChange('F')">首页</a>
    <a style="margin-right: 20px;" @click="pageChange('U')">上一页</a>
    <a style="margin-right: 20px;" @click="pageChange('N')">下一页</a>
    <a style="margin-right: 20px;" @click="pageChange('E')">尾页</a>
</span>
</template>
<script setup lang="ts">
import axios from "axios";
import { onMounted,ref } from "vue";
import { useRouter } from "vue-router";

const router=useRouter();

const Get=(Did:number)=>{

    router.push({
        name:"GetDoctor",
        params:{
            id:Did
        }
    })

}


//导出
const Exopre=()=>{
    axios.post('https://localhost:7133/api/Doctor/ExpDoctor?Fpath='+'D:\\Users\\27084\\王梦真11.29月考题\\Doctorinfos.xlsx')
    .then(res=>{
        if(res.data>0){
            alert("导出成功");
        }
        else{
            alert("导出失败");
        }
    })
}


///删除
const Del=(Did:number)=>{

    if(confirm("你确定要删除吗？"))
    {
        axios.get('https://localhost:7133/api/Doctor/DelDoctor',
        {
            params:{
                DoctorId:Did
            }
        }
        )

        .then(res=>{
            if(res.data>0){
                alert("删除成功");
                Lodata();
            }
            else{
                alert("删除失败");
            }
        })

    }

}

const DoctorName=ref("");
const Pos=ref("");

const info=ref([{
    DoctorName:"",
    College:"",
    Pos:"",
    DoctorImg:"",
    KeiShiName:"",
    DoctorId:0

}])

const pageInfo=ref({
    pageIndex:1,
    pageSize:2,
    totalcount:0,
    pagecount:0
})


onMounted(()=>{
    Lodata();
})

const Lodata=()=>{
    axios.get('https://localhost:7133/api/Doctor/ShowDoctor',
    {
        params:{
            DoctorName:DoctorName.value,
            Pos:Pos.value,
            pageIndex:pageInfo.value.pageIndex,
            pageSize:pageInfo.value.pageSize
        }
    }
    
    )
    .then(res=>{
        pageInfo.value.totalcount=res.data.TotalCount;
        pageInfo.value.pagecount=res.data.PageCount;
        info.value=res.data.Data_Info;
      
    })
}


//分页
const pageChange=(choose:string)=>{
    
    switch(choose){
        case 'F':
            pageInfo.value.pageIndex=1;
            break;
            case 'U':
            pageInfo.value.pageIndex=pageInfo.value.pageIndex-1;
            break;
            case 'N':
            pageInfo.value.pageIndex=pageInfo.value.pageIndex+1;
            break;
            case 'E':
            pageInfo.value.pageIndex=pageInfo.value.pagecount;
            break;
    }
    Lodata();

}

</script>